create or replace function deletePosterminalModel(
	out xml, inout xml
	)
as
$$
	declare
		-- alias is name for stored procedure parameters
		executeStatusData 			alias for $1;
		posterminalModelData		alias for $2;
		
		-- variable for node data
		vIdModel 		bigint 	:= null;
		
		-- node path
		vIdNode			varchar(100) := '/posterminalmodel/@id';
		
		
	begin
		-- get data from xml
		vIdModel := cast(extract_value(vIdNode, posterminalModelData) as bigint);
		
		-- first insert into trace table previous data
		insert into posterminalModelTrace(idPosterminalModel, idPosterminalProducer, namePosterminalModel)
			select idPosterminalModel, idPosterminalProducer, namePosterminalModel from PosterminalModel poel
				where
					poel.idPosterminalModel = vIdModel
		;
		
		-- delete data in table
		delete from posterminalModel poel
			where
				poel.idPosterminalModel = vIdModel
		;
		
		executeStatusData := statusCall(successcode(), deleteText()); -- status data
		return;

	end;
$$ language plpgsql VOLATILE;